<template>
  <div class="address">
    <van-sticky class="mb10">
      <topbar right-text="添加地址" @click-right="onClickRight"></topbar>
    </van-sticky>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
      class="list-box"
    >
      <van-cell class="order-item" v-for="(item,index) of addressList" :key="index">
        <van-row gutter="10" type="flex" align="center">
          <van-col span="4">
            <van-image fit="contain" :src="icoAddress" />
          </van-col>
          <van-col span="20" @click="select(item)">
            <van-row class="mb10">
              <van-col span="8">{{item.consignee}}</van-col>
              <van-col span="11" style="color: #7D7D7D;">{{item.mobliePhone}}</van-col>
              <van-col span="5" style="text-align: right;color: #8C8B8B;" @click="edit(item)">编辑</van-col>
            </van-row>
            <div
              class="van-multi-ellipsis--l2"
            >{{item.provinceName}}{{item.cityName}}{{item.areaName}}{{item.address}}</div>
          </van-col>
        </van-row>
      </van-cell>
    </van-list>
  </div>
</template>
<script>
export default {
  data() {
    return {
      isApp: this.$store.state.auth.isApp,
      active: 0,
      onLoading: false,
      loading: false,
      finished: true,
      icoAddress: require("../../assets/img/ico-address.png"),
      addressList: []
    };
  },
  mounted() {
    if(this.isApp){
      window.yangcheJS.setTitleBar(
              false,//是否隐藏导航栏
              "收货地址",//页面标题
              "添加地址",//右上角文案
              "onClickRight()",//右上角js
              "refreshView",//返回上一级功能
              ""//导航栏颜色默认白色
      )
    }
    this.getAddressList();
  },
  methods: {
    select(item){
      sessionStorage.setItem('addressDetail',JSON.stringify(item))
      if(this.$route.params.back){  
        history.go(-1)
      }
    },
    edit(item) {
      this.$router.push({
        name: "address-add",
        params: {
          item: item
        }
      });
    },
    getAddressList() {
      if(this.isApp){
        let date={};
        let content=JSON.stringify({"targetUrl":"https://mobile.yangche51.com/#/address/address","data":date});
        window.yangcheJS.WebViewJavascriptBridge(
                "openPage",
                content,
                "",
                "address",
                ""
        )
      }else {
        this.$http.get("//app.yangche51.com/6_1/usercenter/address/getaddresslist_1_0.ashx").then(res=>
        {
          this.addressList = res.data.body;
        });
      }
    },
    onClickLeft() {
      history.go(-1);
    },
    onLoad() {},
    onClickRight() {
      this.$router.push({
        name: "address-add"
      });
    }
  }
};
</script>
<style lang="less" scoped>
.address {
  .van-nav-bar__text {
    color: #323233;
  }
}
.list-box {
  min-height: 100%;
  .order-item {
    background: #fff;
  }
  .van-card {
    background: #fff;
  }
  .van-button {
    height: 100%;
  }
}
</style>